home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Languguage OS 2
/
Languguage OS II Version 10-94 (Knowledge Media)(1994).ISO
/
language
/
embedded
/
68hc11
/
fuzzy11a.arc
/
FUZZY11A.LST
< prev
Wrap
File List
|
1991-12-04
|
34KB
|
508 lines
M68HC11 Portable Cross Assembler 0.05 MS-DOS/PC-DOS Page 1
Thu Oct 10 16:08:33 1991
Command line:
d:\pasm\PASMHC11.EXE -l FUZZY11A.lst FUZZY11A.ASM
Options list:
ON - b - Printing of macro definitions
ON - c - Printing of macro calls
OFF - d - Placing of symbolic debugging information in COFF
ON - e - Printing of macro expansions (changed)
ON - f - Printing of conditional directives
OFF - g - Printing of generated constants list
OFF - q - Expanding and printing of structured syntax
OFF - s - Printing of symbol table
OFF - u - Printing of conditional unassembled source
OFF - x - Printing of cross reference table
OFF - m - Suppress printing of error messages
ON - w - Printing of warning messages
OFF - v - Suppress printing of updated status
OFF - y - Enabling of sgs extensions
ON - o - Create object code
ON - - Formatting of source line listing
Create listing file - l - FUZZY11A.lst
Xdefs:
NONE
Xrefs:
NONE
Input file(s): FUZZY11A.ASM (241 lines)
Output file: FUZZY11A.o
Listing file: FUZZY11A.lst
M68HC11 Portable Cross Assembler 0.05 FUZZY11A.ASM Page 2
Thu Oct 10 16:08:33 1991
Options - MD,MC,NOG,NOU,W,NOMEX,CL,FMT,O
LINE S PC OPCO OPERANDS S LABEL MNEMO OPERANDS COMMENT
00001 * Fuzzy Logic Inferrence Engine
00002 *
00003 *** Data structures and variables
00004 *
00005 opt mex
00006 A 0000 ORG $0000 ;Beginning of HC11 RAM
00007 A 0000 08 A CURRENT_INS RMB 8 ;Storage for 8 8-bit inputs
00008 A 0008 20 A FUZ_OUTS RMB 32 ;Storage for fuzzy outputs
00009 A 0028 04 A COG_OUTS RMB 4 ;Defuzzified outputs
00010 A 002c 01 A LOWEST_IF RMB 1 ;Holds min grade of IF parts
00011 A 002d 02 A SUM_OF_FUZ RMB 2 ;11-bit sum of fuzzy outs
00012 A 002f 03 A SUM_OF_PROD RMB 3 ;19-bit sum of products
00013 A 0032 01 A COGDEX RMB 1 ;Current out # for COG loop 0->4
00014 A 0033 01 A SUMDEX RMB 1 ;Index for sum loop 8->0
00015
00016 A b600 ORG $B600 Beginning of HC11 EEPROM
00017 A b600 b610 A IN_MF_PTRS FDB IN0MF ;Addr of MF data for input 0
00018 A b602 b618 A FDB IN1MF ;Addr of MF data for input 1
00019 A b604 b61c A FDB IN2MF ;Addr of MF data for input 2
00020 A b606 b630 A FDB IN3MF ;Addr of MF data for input 3
00021 A b608 b644 A FDB IN4MF ;Addr of MF data for input 4
00022 A b60a b644 A FDB IN5MF ;Addr of MF data for input 5
00023 A b60c b644 A FDB IN6MF ;Addr of MF data for input 6
00024 A b60e b644 A FDB IN7MF ;Addr of MF data for input 7
00025 *
00026 * Input membership functions are defined by four 8-bit values per
00027 * input label. Up to 8 labels per input so max size of MF data
00028 * structure is 8*8*4=256 bytes. Unused labels take no space.
00029 * Membership functions are trapezoids with the base greater than or
00030 * equal to the top. Values are entered into this program as the
00031 * X coordinates of 4 points but are stored as 2 points and 2 slopes.
00032 *
00033 ***** MACRO Definition for input membership functions
00034 *
00035 MACRO DEF INMF MACR ;For input membership functions
00036 FCB \0 ;First inflection point
00037 IFNE \1-\0 ;Check for divide by zero
00038 FCB ($FF+((\1-\0)/3))/(\1-\0) ;If not, calc slope
00039 ENDC
00040 IFEQ \1-\0 ;Check for divide by zero
00041 FCB $00 ;Indicates vertical slope
00042 ENDC
00043 FCB \2 ;Third inflection point
00044 IFNE \3-\2 ;Check for divide by zero
00045 FCB ($FF+((\3-\2)/3))/(\3-\2) ;If not, calc slope
00046 ENDC
00047 IFEQ \3-\2 ;Check for divide by zero
00048 FCB $00 ;Indicates vertical slope
00049 ENDC
00050 ENDM
00051 *
00052 *****
M68HC11 Portable Cross Assembler 0.05 FUZZY11A.ASM Page 3
Thu Oct 10 16:08:33 1991
Options - MD,MC,NOG,NOU,W,MEX,CL,FMT,O
LINE S PC OPCO OPERANDS S LABEL MNEMO OPERANDS COMMENT
00053 A b610 b610 A INPUT_MFS EQU * ;Input membership functions
00054
00055 A b610 b610 A IN0MF EQU * ;(0) ROTATION
00056 MACRO INV INMF 0,0,0,8*4 ; (0) STOPPED
00056 +A b610 00 A FCB 0 ;First inflection point
00056 + IFNE 0-0 ;Check for divide by zero
00056 + ENDC
00056 + IFEQ 0-0 ;Check for divide by zero
00056 +A b611 00 A FCB $00 ;Indicates vertical slope
00056 + ENDC
00056 +A b612 00 A FCB 0 ;Third inflection point
00056 + IFNE 8*4-0 ;Check for divide by zero
00056 +A b613 08 A FCB ($FF+((8*4-0)/3))/(8*4-0) ;If not, calc slope
00056 + ENDC
00056 + IFEQ 8*4-0 ;Check for divide by zero
00056 + ENDC
00056 +
00057 MACRO INV INMF 0,8*4,$FF,$FF ; (1) NOT_STOPPED
00057 +A b614 00 A FCB 0 ;First inflection point
00057 + IFNE 8*4-0 ;Check for divide by zero
00057 +A b615 08 A FCB ($FF+((8*4-0)/3))/(8*4-0) ;If not, calc slope
00057 + ENDC
00057 + IFEQ 8*4-0 ;Check for divide by zero
00057 + ENDC
00057 +A b616 ff A FCB $FF ;Third inflection point
00057 + IFNE $FF-$FF ;Check for divide by zero
00057 + ENDC
00057 + IFEQ $FF-$FF ;Check for divide by zero
00057 +A b617 00 A FCB $00 ;Indicates vertical slope
00057 + ENDC
00057 +
00058
00059 A b618 b618 A IN1MF EQU * ;(1) EXAMPLE1
00060 MACRO INV INMF $20,$40,$60,$A0 ; (0) TEST1
00060 +A b618 20 A FCB $20 ;First inflection point
00060 + IFNE $40-$20 ;Check for divide by zero
00060 +A b619 08 A FCB ($FF+(($40-$20)/3))/($40-$20) ;If not, calc slope
00060 + ENDC
00060 + IFEQ $40-$20 ;Check for divide by zero
00060 + ENDC
00060 +A b61a 60 A FCB $60 ;Third inflection point
00060 + IFNE $A0-$60 ;Check for divide by zero
00060 +A b61b 04 A FCB ($FF+(($A0-$60)/3))/($A0-$60) ;If not, calc slope
00060 + ENDC
00060 + IFEQ $A0-$60 ;Check for divide by zero
00060 + ENDC
00060 +
00061
00062 A b61c b61c A IN2MF EQU * ;(2) TEMPERATURE
00063 MACRO INV INMF 2*0,2*0,2*40,2*50 ; (0) COLD
00063 +A b61c 00 A FCB 2*0 ;First inflection point
00063 + IFNE 2*0-2*0 ;Check for divide by zero
M68HC11 Portable Cross Assembler 0.05 FUZZY11A.ASM Page 4
Thu Oct 10 16:08:33 1991
Options - MD,MC,NOG,NOU,W,MEX,CL,FMT,O
LINE S PC OPCO OPERANDS S LABEL MNEMO OPERANDS COMMENT
00063 + ENDC
00063 + IFEQ 2*0-2*0 ;Check for divide by zero
00063 +A b61d 00 A FCB $00 ;Indicates vertical slope
00063 + ENDC
00063 +A b61e 50 A FCB 2*40 ;Third inflection point
00063 + IFNE 2*50-2*40 ;Check for divide by zero
00063 +A b61f 0d A FCB ($FF+((2*50-2*40)/3))/(2*50-2*40) ;If not, calc slope
00063 + ENDC
00063 + IFEQ 2*50-2*40 ;Check for divide by zero
00063 + ENDC
00063 +
00064 MACRO INV INMF 2*40,2*50,2*60,2*70 ; (1) COOL
00064 +A b620 50 A FCB 2*40 ;First inflection point
00064 + IFNE 2*50-2*40 ;Check for divide by zero
00064 +A b621 0d A FCB ($FF+((2*50-2*40)/3))/(2*50-2*40) ;If not, calc slope
00064 + ENDC
00064 + IFEQ 2*50-2*40 ;Check for divide by zero
00064 + ENDC
00064 +A b622 78 A FCB 2*60 ;Third inflection point
00064 + IFNE 2*70-2*60 ;Check for divide by zero
00064 +A b623 0d A FCB ($FF+((2*70-2*60)/3))/(2*70-2*60) ;If not, calc slope
00064 + ENDC
00064 + IFEQ 2*70-2*60 ;Check for divide by zero
00064 + ENDC
00064 +
00065 MACRO INV INMF 2*60,2*70,2*80,2*90 ; (2) WARM
00065 +A b624 78 A FCB 2*60 ;First inflection point
00065 + IFNE 2*70-2*60 ;Check for divide by zero
00065 +A b625 0d A FCB ($FF+((2*70-2*60)/3))/(2*70-2*60) ;If not, calc slope
00065 + ENDC
00065 + IFEQ 2*70-2*60 ;Check for divide by zero
00065 + ENDC
00065 +A b626 a0 A FCB 2*80 ;Third inflection point
00065 + IFNE 2*90-2*80 ;Check for divide by zero
00065 +A b627 0d A FCB ($FF+((2*90-2*80)/3))/(2*90-2*80) ;If not, calc slope
00065 + ENDC
00065 + IFEQ 2*90-2*80 ;Check for divide by zero
00065 + ENDC
00065 +
00066 MACRO INV INMF 2*80,2*90,2*95,2*110 ; (3) HOT
00066 +A b628 a0 A FCB 2*80 ;First inflection point
00066 + IFNE 2*90-2*80 ;Check for divide by zero
00066 +A b629 0d A FCB ($FF+((2*90-2*80)/3))/(2*90-2*80) ;If not, calc slope
00066 + ENDC
00066 + IFEQ 2*90-2*80 ;Check for divide by zero
00066 + ENDC
00066 +A b62a be A FCB 2*95 ;Third inflection point
00066 + IFNE 2*110-2*95 ;Check for divide by zero
00066 +A b62b 08 A FCB ($FF+((2*110-2*95)/3))/(2*110-2*95) ;If not, calc slope
00066 + ENDC
00066 + IFEQ 2*110-2*95 ;Check for divide by zero
00066 + ENDC
M68HC11 Portable Cross Assembler 0.05 FUZZY11A.ASM Page 5
Thu Oct 10 16:08:33 1991
Options - MD,MC,NOG,NOU,W,MEX,CL,FMT,O
LINE S PC OPCO OPERANDS S LABEL MNEMO OPERANDS COMMENT
00066 +
00067 MACRO INV INMF 2*90,2*110,$FF,$FF ; (4) VERY_HOT
00067 +A b62c b4 A FCB 2*90 ;First inflection point
00067 + IFNE 2*110-2*90 ;Check for divide by zero
00067 +A b62d 06 A FCB ($FF+((2*110-2*90)/3))/(2*110-2*90) ;If not, calc slope
00067 + ENDC
00067 + IFEQ 2*110-2*90 ;Check for divide by zero
00067 + ENDC
00067 +A b62e ff A FCB $FF ;Third inflection point
00067 + IFNE $FF-$FF ;Check for divide by zero
00067 + ENDC
00067 + IFEQ $FF-$FF ;Check for divide by zero
00067 +A b62f 00 A FCB $00 ;Indicates vertical slope
00067 + ENDC
00067 +
00068
00069 A b630 b630 A IN3MF EQU * ;(3) DAYS_SINCE_RAIN
00070 MACRO INV INMF $00,$00,$00,$08 ; (0) NONE
00070 +A b630 00 A FCB $00 ;First inflection point
00070 + IFNE $00-$00 ;Check for divide by zero
00070 + ENDC
00070 + IFEQ $00-$00 ;Check for divide by zero
00070 +A b631 00 A FCB $00 ;Indicates vertical slope
00070 + ENDC
00070 +A b632 00 A FCB $00 ;Third inflection point
00070 + IFNE $08-$00 ;Check for divide by zero
00070 +A b633 20 A FCB ($FF+(($08-$00)/3))/($08-$00) ;If not, calc slope
00070 + ENDC
00070 + IFEQ $08-$00 ;Check for divide by zero
00070 + ENDC
00070 +
00071 MACRO INV INMF $00,$10,$10,$18 ; (1) SHORT
00071 +A b634 00 A FCB $00 ;First inflection point
00071 + IFNE $10-$00 ;Check for divide by zero
00071 +A b635 10 A FCB ($FF+(($10-$00)/3))/($10-$00) ;If not, calc slope
00071 + ENDC
00071 + IFEQ $10-$00 ;Check for divide by zero
00071 + ENDC
00071 +A b636 10 A FCB $10 ;Third inflection point
00071 + IFNE $18-$10 ;Check for divide by zero
00071 +A b637 20 A FCB ($FF+(($18-$10)/3))/($18-$10) ;If not, calc slope
00071 + ENDC
00071 + IFEQ $18-$10 ;Check for divide by zero
00071 + ENDC
00071 +
00072 MACRO INV INMF $10,$20,$28,$40 ; (2) MEDIUM
00072 +A b638 10 A FCB $10 ;First inflection point
00072 + IFNE $20-$10 ;Check for divide by zero
00072 +A b639 10 A FCB ($FF+(($20-$10)/3))/($20-$10) ;If not, calc slope
00072 + ENDC
00072 + IFEQ $20-$10 ;Check for divide by zero
00072 + ENDC
M68HC11 Portable Cross Assembler 0.05 FUZZY11A.ASM Page 6
Thu Oct 10 16:08:33 1991
Options - MD,MC,NOG,NOU,W,MEX,CL,FMT,O
LINE S PC OPCO OPERANDS S LABEL MNEMO OPERANDS COMMENT
00072 +A b63a 28 A FCB $28 ;Third inflection point
00072 + IFNE $40-$28 ;Check for divide by zero
00072 +A b63b 0a A FCB ($FF+(($40-$28)/3))/($40-$28) ;If not, calc slope
00072 + ENDC
00072 + IFEQ $40-$28 ;Check for divide by zero
00072 + ENDC
00072 +
00073 MACRO INV INMF $30,$40,$50,$60 ; (3) LONG
00073 +A b63c 30 A FCB $30 ;First inflection point
00073 + IFNE $40-$30 ;Check for divide by zero
00073 +A b63d 10 A FCB ($FF+(($40-$30)/3))/($40-$30) ;If not, calc slope
00073 + ENDC
00073 + IFEQ $40-$30 ;Check for divide by zero
00073 + ENDC
00073 +A b63e 50 A FCB $50 ;Third inflection point
00073 + IFNE $60-$50 ;Check for divide by zero
00073 +A b63f 10 A FCB ($FF+(($60-$50)/3))/($60-$50) ;If not, calc slope
00073 + ENDC
00073 + IFEQ $60-$50 ;Check for divide by zero
00073 + ENDC
00073 +
00074 MACRO INV INMF $50,$70,$FF,$FF ; (4) VERY_LONG
00074 +A b640 50 A FCB $50 ;First inflection point
00074 + IFNE $70-$50 ;Check for divide by zero
00074 +A b641 08 A FCB ($FF+(($70-$50)/3))/($70-$50) ;If not, calc slope
00074 + ENDC
00074 + IFEQ $70-$50 ;Check for divide by zero
00074 + ENDC
00074 +A b642 ff A FCB $FF ;Third inflection point
00074 + IFNE $FF-$FF ;Check for divide by zero
00074 + ENDC
00074 + IFEQ $FF-$FF ;Check for divide by zero
00074 +A b643 00 A FCB $00 ;Indicates vertical slope
00074 + ENDC
00074 +
00075
00076 A b644 b644 A IN4MF EQU * ;Not used
00077 A b644 b644 A IN5MF EQU * ;Not used
00078 A b644 b644 A IN6MF EQU * ;Not used
00079 A b644 b644 A IN7MF EQU * ;Not used
00080
00081 A b644 b644 A SGLTN_POS EQU * ;Output singleton positions
00082 A b644 b644 A OUT0MF EQU * ;(0) WATERING_TIME
00083 A b644 00 A FCB $00 ;(0) CUT_OFF
00084 A b645 10 A FCB $10 ;(1) DECREASE_GREATLY
00085 A b646 40 A FCB $40 ;(2) DECREASE
00086 A b647 80 A FCB $80 ;(3) NORMAL
00087 A b648 b0 A FCB $B0 ;(4) INCREASE
00088 A b649 f0 A FCB $F0 ;(5) INCREASE_GREATLY
00089 A b64a 0000 A FCB 0,0 ;Unused; Must fill 8 per output
00090 A b64c 0000000000A OUT1MF FCB 0,0,0,0,0,0,0,0 ;Not used
00091 A b654 0000000000A OUT2MF FCB 0,0,0,0,0,0,0,0 ;Not used
M68HC11 Portable Cross Assembler 0.05 FUZZY11A.ASM Page 7
Thu Oct 10 16:08:33 1991
Options - MD,MC,NOG,NOU,W,MEX,CL,FMT,O
LINE S PC OPCO OPERANDS S LABEL MNEMO OPERANDS COMMENT
00092 A b65c 0000000000A OUT3MF FCB 0,0,0,0,0,0,0,0 ;Not used
00093 *
00094 * Each If part is of the form 00AA AXXX where AAA is a label (0-7)
00095 * and XXX is an input (0-7). If parts are connected by ANDs. A rule
00096 * may have any number of if parts (usually 2-8). Then parts are of
00097 * the form 100Y YCCC where the MSB set indicates a then part, YY is
00098 * the output number (0-3), and CCC is the output label (singleton
00099 * 0-7). A rule may have any number of then parts (usually 1 or 2).
00100 * A $FF indicates the end of a series of rules (number not limited).
00101 *
00102 * FCB INx + 8*LABa ;If input XXX is label AAA
00103 * FCB $80+8*OUTy+LABc ;Then output YY is label CCC
00104
00105 A b664 b664 A RULE_START EQU * ;Start of first rule
00106 * Example rule: If TEMPERATURE is VERY_HOT and DAYS_SINCE_RAIN is LONG
00107 * Then WATERING_TIME is INCREASE_GREATLY
00108 A b664 221b85 A RULE_1 FCB 2+(8*4),3+(8*3),$80+(8*0)+5
00109 A b667 ff A END_OF_RULE FCB $FF
00110
00111 ***** Fuzzy Inferrence Engine Starts Here
00112 *
00113 A b66b ORG $B66B
00114 A b66b ce 0008 A INFER_TOP LDX #FUZ_OUTS ;Point at first fuzzy output
00115 A b66e 86 20 A LDAA #32 ;32 fuzzy outputs
00116 A b670 6f 00 A CLR_OUTS CLR 0,X ;Clear a fuzzy output
00117 A b672 08 INX ;Point at next
00118 A b673 4a DECA ;Loop index
00119 A b674 26 fa b670 BNE CLR_OUTS ;Continue till all fuzzy outs 0
00120 A b676 18ce b664 A LDY #RULE_START ;Point to start of 1st rule
00121 A b67a 86 ff A RULE_TOP LDAA #$FF ;Begin processing rule string
00122 A b67c 97 2c A STAA LOWEST_IF ;Will hold grade of min if part
00123 A b67e 18e6 00 A IF_LOOP LDAB 0,Y ;Get rule byte 00AA AXXX; If X is A
00124 A b681 2b 63 b6e6 BMI THEN_LOOP ;If MSB=1, exit to then loop
00125 A b683 ce 0000 A LDX #CURRENT_INS ;Point at current input data area
00126 A b686 c4 07 A ANDB #$07 ;Save only input number
00127 A b688 37 PSHB ;Will need input # again
00128 A b689 3a ABX ;Point to specific input data
00129 A b68a a6 00 A LDAA 0,X ;Get current input data
00130 A b68c ce b600 A LDX #IN_MF_PTRS ;Point at offsets for input MFs
00131 A b68f 33 PULB ;Recover input number 0000 0XXX
00132 A b690 3a ABX ;Point at pointer for this input #
00133 A b691 ee 00 A LDX 0,X ;Get pointer into MF data area
00134 A b693 18e6 00 A LDAB 0,Y ;Get rule if part 00AA AXXX
00135 A b696 c4 38 A ANDB #$38 ;00AA A000 is 8 times AAA
00136 A b698 54 LSRB ;000A AA00 4 times AAA
00137 A b699 3a ABX ;X points at MF points & slopes
00138 A b69a a1 00 A CMPA 0,X ;Compare input data to MF pt1
00139 A b69c 24 03 b6a1 BHS NOT_SEG0 ;Branch if not segment zero
00140 A b69e 5f CLRB ;In seg 0 grade is zero
00141 A b69f 20 25 b6c6 BRA HAVE_GRADE ;Have grade of membership
00142 A b6a1 a1 02 A NOT_SEG0 CMPA 2,X ;Compare input data to MF pt2
00143 A b6a3 22 11 b6b6 BHI IS_SEG2 ;Branch if segment two
M68HC11 Portable Cross Assembler 0.05 FUZZY11A.ASM Page 8
Thu Oct 10 16:08:33 1991
Options - MD,MC,NOG,NOU,W,MEX,CL,FMT,O
LINE S PC OPCO OPERANDS S LABEL MNEMO OPERANDS COMMENT
00144 A b6a5 e6 01 A LDAB 1,X ;Slope1 -> B
00145 A b6a7 27 09 b6b2 BEQ JAM_FF ;If vert slope, jam $FF
00146 A b6a9 a0 00 A SUBA 0,X ;Input value - pt1 -> A
00147 A b6ab 3d MUL ;Grade in B if D < $100
00148 A b6ac 1a83 0100 A CPD #$100 ;Check for overflow
00149 A b6b0 25 14 b6c6 BLO HAVE_GRADE ;If < $100 grade OK in B
00150 A b6b2 c6 ff A JAM_FF LDAB #$FF ;Else limit B to $FF
00151 A b6b4 20 10 b6c6 BRA HAVE_GRADE ;Have grade of membership
00152 A b6b6 e6 03 A IS_SEG2 LDAB 3,X ;Slope2 -> B
00153 A b6b8 a0 02 A SUBA 2,X ;Input value - pt2 -> A
00154 A b6ba 3d MUL ;Grade in B if D < $100
00155 A b6bb 1a83 0100 A CPD #$100 ;Check for overflow
00156 A b6bf 25 02 b6c3 BLO B_OK ;If < $100 value in B OK
00157 A b6c1 c6 ff A LDAB #$FF ;Else limit B to $FF
00158 A b6c3 86 ff A B_OK LDAA #$FF ;Grade should be $FF - (B)
00159 A b6c5 10 SBA ;Grade of membership in B
00160 A b6c6 d1 2c A HAVE_GRADE CMPB LOWEST_IF ;Is grade lowest so far ?
00161 A b6c8 24 18 b6e2 BHS NOT_LOWR ;Branch if not lower
00162 A b6ca d7 2c A STAB LOWEST_IF ;If lower, replace lowest if
00163 A b6cc 26 14 b6e2 BNE NOT_LOWR ;Skip ahead if not zero
00164 A b6ce 1808 FIND_THEN INY ;Adv rule pointer to then part
00165 A b6d0 18e6 00 A LDAB 0,Y ;Get next rule byte
00166 A b6d3 2a f9 b6ce BPL FIND_THEN ;MSB set means its a then part
00167 A b6d5 1808 FIND_IF INY ;Adv rule pointer to if part
00168 A b6d7 18e6 00 A LDAB 0,Y ;Get next rule byte
00169 A b6da 2a 9e b67a BPL RULE_TOP ;MSB clear means its an if part
00170 A b6dc c1 ff A CMPB #$FF ;$FF is no more rules marker
00171 A b6de 26 f5 b6d5 BNE FIND_IF ;Continue looking for if or $FF
00172 A b6e0 20 20 b702 BRA DEFUZ ;When all rules done, go defuzzify
00173 A b6e2 1808 NOT_LOWR INY ;Point to next rule byte
00174 A b6e4 20 98 b67e BRA IF_LOOP ;Continue for all if parts
00175 A b6e6 ce 0008 A THEN_LOOP LDX #FUZ_OUTS ;Point at fuzzy outputs
00176 A b6e9 c4 1f A ANDB #$1F ;Save 8 times out # + label #
00177 A b6eb 3a ABX ;X points at fuzzy output
00178 A b6ec 96 2c A LDAA LOWEST_IF ;Grade of membership for rule
00179 A b6ee a1 00 A CMPA 0,X ;Compare to fuzzy output
00180 A b6f0 25 02 b6f4 BLO NOT_HIER ;Branch if not higher
00181 A b6f2 a7 00 A STAA 0,X ;Grade is higher so update
00182 A b6f4 1808 NOT_HIER INY ;Point to next rule byte
00183 A b6f6 18e6 00 A LDAB 0,Y ;Get rule byte
00184 A b6f9 2b 03 b6fe BMI CHK_END ;If MSB=0 its a new rule
00185 A b6fb 7e b67a A JMP RULE_TOP ;Else process next rule byte
00186 A b6fe c1 ff A CHK_END CMPB #$FF ;Check for end of rules flag
00187 A b700 26 e4 b6e6 BNE THEN_LOOP ;If not $FF, must be a then part
00188 A b702 18ce b644 A DEFUZ LDY #SGLTN_POS ;Point at 1st output singleton
00189 A b706 ce 0008 A LDX #FUZ_OUTS ;Point at 1st fuzzy output
00190 A b709 7f 0032 A CLR COGDEX ;Loop index will run from 0->4
00191 A b70c c6 08 A COG_LOOP LDAB #8 ;8 fuzzy outs per COG output
00192 A b70e d7 33 A STAB SUMDEX ;Inner loop runs 8->0
00193 A b710 cc 0000 A LDD #$0000 ;Used for quicker clears
00194 A b713 dd 2d A STD SUM_OF_FUZ ;Sum of fuzzy outputs
00195 A b715 dd 30 A STD SUM_OF_PROD+1 ;Low 16-bits of sum of products
M68HC11 Portable Cross Assembler 0.05 FUZZY11A.ASM Page 9
Thu Oct 10 16:08:33 1991
Options - MD,MC,NOG,NOU,W,MEX,CL,FMT,O
LINE S PC OPCO OPERANDS S LABEL MNEMO OPERANDS COMMENT
00196 A b717 97 2f A STAA SUM_OF_PROD ;Upper 8-bits
00197 A b719 e6 00 A SUM_LOOP LDAB 0,X ;Get a fuzzy output
00198 A b71b 4f CLRA ;Clear upper 8-bits
00199 A b71c d3 2d A ADDD SUM_OF_FUZ ;Add to sum of fuzzy outputs
00200 A b71e dd 2d A STD SUM_OF_FUZ ;Update RAM variable
00201 A b720 a6 00 A LDAA 0,X ;Get fuzzy output again
00202 A b722 18e6 00 A LDAB 0,Y ;Get Output singleton position
00203 A b725 3d MUL ;Position times weight
00204 A b726 d3 30 A ADDD SUM_OF_PROD+1 ;Low 16-bits of sum of products
00205 A b728 dd 30 A STD SUM_OF_PROD+1 ;Update low 16-bits
00206 A b72a 96 2f A LDAA SUM_OF_PROD ;Upper 8-bits
00207 A b72c 89 00 A ADCA #0 ;Add carry from 16-bit add
00208 A b72e 97 2f A STAA SUM_OF_PROD ;Upper 8-bits of 24-bit sum
00209 A b730 1808 INY ;Point at next singleton pos.
00210 A b732 08 INX ;Point at next fuzzy output
00211 A b733 7a 0033 A DEC SUMDEX ;Inner loop index
00212 A b736 26 e1 b719 BNE SUM_LOOP ;For all labels this output
00213 A b738 3c PSHX ;Save index for now
00214 A b739 4f CLRA ;In case divide by zero
00215 A b73a de 2d A LDX SUM_OF_FUZ ;Demominator for divide
00216 A b73c 27 18 b756 BEQ SAV_OUT ;Branch if denominator is 0
00217 A b73e 7d 002f A TST SUM_OF_PROD ;See if more than 16-bit
00218 A b741 26 07 b74a BNE NUM_BIG ;If not zero, # is > 16-bits
00219 A b743 dc 30 A LDD SUM_OF_PROD+1 ;Numerator for divide
00220 A b745 02 IDIV ;Result in low 8-bits of X
00221 A b746 8f XGDX ;Result now in B
00222 A b747 17 TBA ;Move result to A
00223 A b748 20 0c b756 BRA SAV_OUT ;Go save output
00224 A b74a dc 2f A NUM_BIG LDD SUM_OF_PROD ;Numerator upper 16 of 24-bit
00225 A b74c 7d 0031 A TST SUM_OF_PROD+2 ;Check for rounding error
00226 A b74f 2a 03 b754 BPL NO_ROUND ;If MSB clear, don't round
00227 A b751 c3 0001 A ADDD #1 ;Round numerator up 1
00228 A b754 03 NO_ROUND FDIV ;D/X -> X, use upper 8 of 16
00229 A b755 8f XGDX ;Result now in A
00230 A b756 ce 0028 A SAV_OUT LDX #COG_OUTS ;Point to 1st defuz output
00231 A b759 d6 32 A LDAB COGDEX ;Curent output number
00232 A b75b 3a ABX ;Point to correct output
00233 A b75c a7 00 A STAA 0,X ;Update defuzzified output
00234 A b75e 38 PULX ;Recover index
00235 A b75f 5c INCB ;Increment loop index
00236 A b760 d7 32 A STAB COGDEX ;Update
00237 A b762 c1 04 A CMPB #4 ;Done with all four outs?
00238 A b764 26 a6 b70c BNE COG_LOOP ;If not, continue loop
00239
00240 * Inference engine has completed one pass of all rules.
00241
***** warning 24: END statement is missing
M68HC11 Portable Cross Assembler 0.05 Page 10
Thu Oct 10 16:08:33 1991
Total number of errors: 0
Total number of warnings: 1
Total number of lines: 241
Number of bytes in section ASCT: 407
Number of bytes in program: 407